package com.lykj.llw.box.ui.activity

import android.os.Bundle
import android.util.Log
import com.gyf.immersionbar.BarHide
import com.gyf.immersionbar.ImmersionBar
import com.lykj.lib_base.base.BaseActivity
import com.lykj.lib_base.internal.extfun.clickWithTrigger
import com.lykj.llw.box.adapter.banner.PreviewBannerAdapter
import com.lykj.llw.box.databinding.ActMultiImageDisplayBinding
import com.youth.banner.listener.OnPageChangeListener

/**
 * ================================================
 * 多图预览
 * ================================================
 *
 * @author gosha
 * @date 2023/12/7-15:17
 */
class MultiImageDisplayActivity : BaseActivity() {
    lateinit var binding: ActMultiImageDisplayBinding

    private val mData = ArrayList<String>()
    private val TAG = "MultiImageDisplay"
    private var mIndex = 0

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = ActMultiImageDisplayBinding.inflate(layoutInflater)
        setContentView(binding.root)
        initUI()
        initData()
        setListener()
    }

    override fun onResume() {
        super.onResume()

        ImmersionBar.with(this)
            .transparentBar()
//            .statusBarDarkFont(true) //状态栏字体是深色，不写默认为亮色
//            .navigationBarDarkIcon(true)
            .hideBar(BarHide.FLAG_HIDE_NAVIGATION_BAR)
            .navigationBarEnable(false)
            .init()
    }

    override fun initUI() {
    }

    override fun initData() {
        //设置数据
        if (intent.getStringArrayListExtra("pics") != null) {
            mData.addAll(intent.getStringArrayListExtra("pics")!!)
        }
        mIndex = intent.getIntExtra("index", 0)
        binding.tvTitle.text = "${mIndex + 1} / ${mData.size}"
        binding.bannerDisplay.addBannerLifecycleObserver(this)
            .setAdapter(PreviewBannerAdapter(mData))
            .addOnPageChangeListener(object : OnPageChangeListener {
                override fun onPageScrolled(
                    position: Int,
                    positionOffset: Float,
                    positionOffsetPixels: Int
                ) {
                }

                override fun onPageSelected(position: Int) {
                    binding.tvTitle.text = "${position + 1} / ${mData.size}"
                    Log.e(TAG, mData[position])
                }

                override fun onPageScrollStateChanged(state: Int) {}
            })
        binding.bannerDisplay.setCurrentItem(mIndex + 1, false)
    }

    override fun setListener() {
        binding.ivClose.clickWithTrigger {
            finish()
        }
    }
}